package fun.wlfj.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import fun.wlfj.factory.CashSystemFactory;
import fun.wlfj.vo.PayList;
import fun.wlfj.vo.Product;
import fun.wlfj.vo.User;

/**
 * Servlet implementation class DeleteProductServlet
 */
@WebServlet("/DeleteProductServlet")
public class DeleteProductServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteProductServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int PayListID = Integer.parseInt(request.getParameter("PayListID"));
		int ProductID = Integer.parseInt(request.getParameter("ProductID"));
		User user = (User)request.getSession().getAttribute("User");
		// 这里我们不检查有效性了
		CashSystemFactory.getPayListDao(user).removeProduct(new PayList(user.getUserID(), PayListID, null), new Product(ProductID, 0));
		response.sendRedirect("makePay.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
